﻿//-----------------------------------------------------------------------------------------------------------
// WBFSSync Project by Omega Frost 
// http://wbfssync.codeplex.com/
//
// WBFSSync is Licensed under the terms of the 
// Microsoft Reciprocal License (Ms-RL)
//-----------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using WBFSe3.Wbfs;
using WBFSe3.Streams;
using WBFSe3.IO;
using WBFSe3.Interfaces;

namespace WBFSe3.Formats
{
    //-------------------------------------------------------------------------------------------------------
    //
    //-------------------------------------------------------------------------------------------------------
    public class WbfsIsoReader : WbfsFormatReader
    {
        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public override WbfsError Initialize(WbfsDriveInfo drive, WbfsPath directory, string file)
        {
            WbfsFileStream stream = new WbfsFileStream(System.IO.Path.Combine(directory.Path, file), 
                WbfsConstants.WiiSectorSize, FileMode.Open, FileAccess.Read, FileShare.Read);

            this.version = 1;
            this.path = new WbfsPath(directory.Path, new String[] { file });
            this.sectorSize = WbfsConstants.WiiSectorSize;

            this.fileLength = stream.Length;
            this.fileSize = stream.QuerySparseSize();

            stream.Close();
            return WbfsError.Ok;
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public override WbfsError Fix()
        {
            return WbfsError.FormatBadFile;
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public override WbfsError ChangeHeader(string name, string code, WbfsRegion region)
        {
            return WbfsError.Ok;
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        protected override WbfsError EmmitStream(FileAccess access, FileShare share, out WbfsStream stream)
        {
            stream = new WbfsFileStream(this.path[0], this.sectorSize, FileMode.Open, access, share);
            return WbfsError.Ok;
        }


        //---------------------------------------------------------------------------------------------------
        //
        //---------------------------------------------------------------------------------------------------
        public override void Close()
        {
            // Do nothing...
        }
    }
}
